<template>
  <div>
    <el-card class="box-card">
      <el-form
        :inline="true"
        @keyup.enter.native="getExportDispatchList()"
        class="dadeFrom"
      >
        <el-date-picker
          class="inputData"
          placeholder="选择日期"
          v-model="valuetimes"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          clearable
        >
        </el-date-picker>
        <!-- 选择场景:<el-select
            v-model="titleval"
            clearable
            style="width: 300px"
            placeholder="选取推送场景"
            @change="changeTitleCon()"
          >
            <el-option
              :label="item.dictName"
              :value="item.dictValue"
              v-for="item in titleList"
              :key="item.id"
            ></el-option>
          </el-select> -->
        <el-button type="primary" @click="getpolling">查询</el-button>
        <!-- <el-button type="success" @click="exportGet()">下载</el-button> -->
        <download-excel
          class="export-btn"
          :data="dataList"
          :fields="jsonFields"
          type="xls"
          name="分场景发送情况.xls"
        >
        <el-button type="success">下载</el-button>
        </download-excel>
      </el-form>
    </el-card>
    <el-card class="box-card" style="margin-top: 10px">
      <el-table
        :data="dataList"
        style="width: 100%"
        v-loading="loading"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(12,42,98, .9)"
      >
        <el-table-column label="场景名称" prop="sceneName" align="center">
        </el-table-column>
        <el-table-column
          label="场景负责人"
          prop="sceneUserName"
          align="center"
          width="100"
        >
        </el-table-column>
        <el-table-column
          label="场景归属部门"
          prop="sceneBelongName"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="调用发起系统"
          prop="sceneSystemName"
          align="center"
        >
        </el-table-column>
        <el-table-column label="发送规模" align="center">
          <el-table-column
            label="普通推送"
            prop="basePushCount"
            align="center"
            width="150"
          >
          </el-table-column>
          <el-table-column
            label="升级推送"
            prop="upgradePushCount"
            align="center"
            width="150"
          >
          </el-table-column>
        </el-table-column>
        <el-table-column label="响应规模" align="center">
          <el-table-column
            label="响应总数"
            prop="pushUpgradeSumCount"
            align="center"
            width="150"
          >
          </el-table-column>
          <el-table-column
            label="普通推送响应"
            prop="baseReadCount"
            align="center"
            width="150"
          >
          </el-table-column>
          <el-table-column
            label="升级推送响应"
            prop="upgradeReadCount"
            align="center"
            width="150"
          >
          </el-table-column>
        </el-table-column>
        <el-table-column label="短信升级规模" prop="shortCount" align="center">
        </el-table-column>
        <el-table-column label="电话升级规模" prop="telCount" align="center">
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 分页 -->
    <!-- <Pagination
          :total="total"
          :pageNum="pageNum"
          :pageSize="pageSize"
          @pageChange="pageChange"
        /> -->
  </div>
</template>
  
  <script>
import axios from "axios";
import JsonExcel from "vue-json-excel";


export default {
  components: {
    DownloadExcel: JsonExcel,
  },
  data() {
    return {
      valuetimes: "", //时间段，绑定的时间
      startTime: "", //开始时间
      endTime: "", //结束时间
      dataForm: {
        timeVal: "",
      },
      dataList: [],
      titleList: [], //场景数据
      jsonFields: {  //导出Excel表格的表头设置
        '场景名称': 'sceneName',
        '场景负责人':'sceneUserName',
        '场景归属部门': 'sceneBelongName',
        '调用发起系统': 'sceneSystemName',
        '普通推送(发送规模)': 'basePushCount',
        '升级推送(发送规模)': 'upgradePushCount',
        '响应总数(响应规模)': 'pushUpgradeSumCount',
        '普通推送响应(响应规模)': 'baseReadCount',
        '升级推送响应(响应规模)': 'upgradeReadCount',
        '短信升级规模': 'shortCount',
        '电话升级规模': 'telCount',
          },
      titleval: null,
      loading: true,
    };
  },

  created() {
    // this.fetchTableList();
  },
  activated() {
    this.fetchTableList2();
    this.fetchTitleList();
  },
  methods: {
    // 获取表格数据
    fetchTableList() {
      let this_ = this;
      this.loading = true;
      console.log(this_.startTime, " this.startTime2");
      console.log(this_.endTime, " this.endTime2");
      this.$http({
        url: this.$http.adornUrl("/cpcplog/getSceneSummary"),
        method: "get",
        params: this.$http.adornParams({
          startTime: this_.startTime,
          endTime: this_.endTime,
          activityId: this.titleval,
        }),
      }).then((res) => {
        //   console.log("res",res);
        if (res.data.code === 0) {
          setTimeout(() => {
            this.loading = false;
            this.dataList = res.data.data;
            // this.dataList = [];
          }, 1000);
          console.log("ssss", res.data.data);
        } else {
          this.dataList = [];
          this.$message.error(res.data.msg);
        }
      });
    },
    // 获取表格数据
    fetchTableList2() {
      let this_ = this;
      this.loading = true;
      console.log(this_.startTime, " this.startTime2");
      console.log(this_.endTime, " this.endTime2");
      this.$http({
        url: this.$http.adornUrl("/cpcplog/getSceneSummary2"),
        method: "get",
        params: this.$http.adornParams({
          startTime: this_.startTime,
          endTime: this_.endTime,
          activityId: this.titleval,
        }),
      }).then((res) => {
        //   console.log("res",res);
        if (res.data.code === 0) {
          setTimeout(() => {
            this.loading = false;
            this.dataList = res.data.data;
            // this.dataList = [];
          }, 1000);
          console.log("ssss", res.data.data);
        } else {
          this.dataList = [];
          this.$message.error(res.data.msg);
        }
      });
    },
    //  字典获取值
    fetchTitleList() {
      this.$http({
        url: this.$http.adornUrl("/sysdictdata/list"),
        method: "get",
        params: this.$http.adornParams({
          dictType: "du_text",
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.titleList = data.page.list;
        }
      });
    },
    changeTitleCon() {
      // const titleOrContent = this.titleval.split(",");
      console.log("this.titleval", this.titleval);
    },
    //格式化时间
    transformTimestamp(result) {
      const date = new Date(result);
      const Y = date.getFullYear() + "";
      const M =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "";
      const D =
        (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + "";
      const dateString = Y + "-" + M + "-" + D;
      // const dateString = Y + M  + D;
      console.log("dateString", dateString); // > dateString 20200110
      return dateString;
    },
    //查询按钮
    getpolling() {
      // this.getDataList();
      if (!this.valuetimes == "") {
        var time1 = new Date(this.valuetimes[0]).getTime();
        var time2 = new Date(this.valuetimes[1]).getTime();
        const start = this.transformTimestamp(time1);
        const end = this.transformTimestamp(time2);
        this.startTime = start;
        this.endTime = end;
        console.log(this.startTime);
        console.log(this.endTime);
        this.fetchTableList();
      } else {
        this.startTime = "";
        this.endTime = "";
        this.fetchTableList();
      }
    },
  },
};
</script>
  <style scoped lang="scss">
@import "../../../assets/scss/span_color";
.button {
  width: 130px;
  height: 40px;
  background: linear-gradient(to bottom, #4eb5e5 0%, #389ed5 100%); /* W3C */
  border: none;
  border-radius: 5px;
  position: relative;
  border-bottom: 4px solid #2b8bc6;
  color: #fbfbfb;
  font-weight: 600;
  font-family: "Open Sans", sans-serif;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.4);
  font-size: 15px;
  text-align: left;
  text-indent: 5px;
  box-shadow: 0px 3px 0px 0px rgba(0, 0, 0, 0.2);
  cursor: pointer;

  /* Just for presentation */
  // display: block;
  margin: 0 auto;
  margin-bottom: 20px;
}
.button:active {
  box-shadow: 0px 2px 0px 0px rgba(0, 0, 0, 0.2);
  top: 1px;
}
.export-btn{
  display: inline-block;
}
.button:after {
  content: "";
  width: 0;
  height: 0;
  display: block;
  border-top: 20px solid #187dbc;
  border-bottom: 20px solid #187dbc;
  border-left: 16px solid transparent;
  border-right: 20px solid #187dbc;
  position: absolute;
  opacity: 0.6;
  right: 0;
  top: 0;
  border-radius: 0 5px 5px 0;
}

/* Button pointing left */

.button.back {
  text-align: right;
  padding-right: 12px;
  box-sizing: border-box;
}
.button.back:after {
  content: "";
  width: 0;
  height: 0;
  display: block;
  border-top: 20px solid #187dbc;
  border-bottom: 20px solid #187dbc;
  border-right: 16px solid transparent;
  border-left: 20px solid #187dbc;
  position: absolute;
  opacity: 0.6;
  left: 0;
  top: 0;
  border-radius: 5px 0 0 5px;
}

/* Single buttons */

.button.site {
  width: 40px;
  text-align: center;
  text-indent: 0;
}
.button.site:after {
  display: none;
}
/deep/ .el-range-editor--medium .el-range-input {
  background-color: transparent;
  color: white;
}
/deep/ .el-table thead.is-group th {
  background-color: rgb(32, 67, 133);
  // border-bottom: 1px solid #73d2ec;
}
</style>
  